﻿<%@ Page Title="" Language="C#" MasterPageFile="~/MasterALSafa.Master" AutoEventWireup="true"
    CodeBehind="Station.aspx.cs" Inherits="School.Pages.Bus.Station" EnableEventValidation="false" %>

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <style type="text/css">
     <%--   #view
        {
            display: none;
        }--%>
    </style>
    <table align="right" dir="rtl" style="width: 964px">
        <tr>
            <td>
                <asp:ScriptManager ID="ScriptManager1" runat="server">
                </asp:ScriptManager>
            </td>
        </tr>
        <tr>
            <td colspan="2">
                <div id="view">
                    <asp:Panel ID="Paneladd" runat="server" Visible="False">
                        <fieldset>
                            <legend id="Legend1" class="opendot" onclick="return Legend1_onclick()" style="font-family: Arial, Helvetica, sans-serif;
                                font-size: x-large">إدخال البيانات</legend>
                            <table dir="rtl" style="width: 100%; float: right">
                                <tr>
                                    <td nowrap="nowrap" style="width: 90px">
                                        المجمع
                                    </td>
                                    <td>
                                        <asp:DropDownList ID="ddCamp1" runat="server" DataTextField="Name" DataValueField="Id"
                                            Width="153" AppendDataBoundItems="True" CssClass="LstCamp" OnSelectedIndexChanged="ddCamp1_SelectedIndexChanged1"
                                            AutoPostBack="True">
                                        </asp:DropDownList>
                                        <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="ddCamp1"
                                            Display="Dynamic" ErrorMessage="*" ForeColor="Red" ValidationGroup="St" InitialValue="-1">*</asp:RequiredFieldValidator>
                                    </td>
                                </tr>
                                <tr>
                                    <td nowrap="nowrap" style="width: 90px">
                                        المنطقة
                                    </td>
                                    <td>
                                        <asp:DropDownList ID="ddlDistrict" runat="server" CssClass="Lstdist" Width="153px"
                                            AppendDataBoundItems="True" DataTextField="Name" DataValueField="Id">
                                        </asp:DropDownList>
                                        <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="ddlDistrict"
                                            Display="Dynamic" ErrorMessage="*" ForeColor="Red" InitialValue="-1" ValidationGroup="St">*</asp:RequiredFieldValidator>
                                    </td>
                                </tr>
                                <tr>
                                    <td nowrap="nowrap" style="width: 90px">
                                        كود المحطة
                                    </td>
                                    <td>
                                        <asp:TextBox ID="txtScode" runat="server" Width="150px"></asp:TextBox>
                                        <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ControlToValidate="txtScode"
                                            Display="Dynamic" ErrorMessage="*" ForeColor="Red" ValidationGroup="St">*</asp:RequiredFieldValidator>
                                        <span id="status"></span>
                                    </td>
                                </tr>
                                <tr>
                                    <td nowrap="nowrap" style="width: 90px">
                                        إسم المحطة
                                    </td>
                                    <td>
                                        <asp:TextBox ID="txtSName" runat="server" Width="150px" MaxLength="50"></asp:TextBox>
                                        <asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" ControlToValidate="txtSName"
                                            Display="Dynamic" ErrorMessage="*" ForeColor="Red" ValidationGroup="St">*</asp:RequiredFieldValidator>
                                        <span id="statusbus"></span>
                                    </td>
                                </tr>
                                <tr>
                                    <td style="width: 90px">
                                    </td>
                                    <td>
                                        <asp:Button ID="Button1" runat="server" OnClick="btnSaveStation_Click" Text="حفظ"
                                            CssClass="graybutton" ValidationGroup="St" />
                                        &nbsp;<asp:Button ID="btnexit" runat="server" CssClass="graybutton" OnClick="btnexit_Click1"
                                            Text="إلغاء" />
                                    </td>
                                </tr>
                                <tr>
                                    <td style="width: 90px">
                                    </td>
                                    <td>
                                        <asp:Label ID="lbltestStation" runat="server" Visible="False"></asp:Label>
                                    </td>
                                </tr>
                            </table>
                        </fieldset>
                    </asp:Panel>
                </div>
            </td>
        </tr>
        <tr>
            <td colspan="2">
                <div id="search">
                    <asp:Panel ID="plsearch" runat="server">
                        <fieldset>
                            <legend id="" class="opendot" style="font-family: Arial, Helvetica, sans-serif; font-size: x-large">
                                البحث</legend>
                            <table dir="rtl" style="width: 100%; float: right">
                                <tr>
                                    <td nowrap="nowrap" style="width: 89px">
                                        كود المحطة
                                    </td>
                                    <td>
                                        <asp:TextBox ID="txtcodeSe" runat="server" Width="150px"></asp:TextBox>
                                    </td>
                                </tr>
                                <tr>
                                    <td nowrap="nowrap" style="width: 89px">
                                        إسم المحطة
                                    </td>
                                    <td>
                                        <asp:TextBox ID="txtNamse" runat="server" Width="150px"></asp:TextBox>
                                    </td>
                                </tr>
                                <tr>
                                    <td style="width: 89px">
                                    </td>
                                    <td>
                                        <asp:Button ID="btnsearch" runat="server" OnClick="btnsearch_Click" Text="بحث" CssClass="graybutton" />
                                    </td>
                                </tr>
                                <tr>
                                    <td style="width: 89px">
                                    </td>
                                    <td>
                                        <asp:Label ID="lbltestStationSearch" runat="server" Visible="False"></asp:Label>
                                    </td>
                                </tr>
                                <tr>
                                    <td style="width: 89px">
                                    </td>
                                    <td>
                                        <asp:Label ID="lblRecordNo" runat="server"></asp:Label>
                                    </td>
                                </tr>
                                <tr>
                                    <td style="width: 89px">
                                    </td>
                                    <td>
                                        <asp:GridView ID="gvdistrict" runat="server" AllowPaging="True" AlternatingRowStyle-CssClass="GridItemAltername"
                                            AutoGenerateColumns="False" CssClass="Grid" DataKeyNames="Id" FooterStyle-CssClass="GridHeaderFooter"
                                            HeaderStyle-CssClass="GridHeaderFooter" OnPageIndexChanging="gvdistrict_PageIndexChanging"
                                            OnRowCancelingEdit="gvdistrict_RowCancelingEdit" OnRowDeleting="gvdistrict_RowDeleting"
                                            OnRowEditing="gvdistrict_RowEditing" 
                                            OnRowUpdating="gvdistrict_RowUpdating" PagerStyle-CssClass="GridPager"
                                            Width="90%" OnRowDataBound="gvdistrict_RowDataBound">
                                            <AlternatingRowStyle CssClass="GridItemAltername" />
                                            <Columns>
                                                <asp:TemplateField>
                                                    <HeaderTemplate>
                                                        م
                                                    </HeaderTemplate>
                                                    <ItemTemplate>
                                                        <%# Container.DataItemIndex + 1 %>
                                                    </ItemTemplate>
                                                </asp:TemplateField>
                                                <asp:BoundField DataField="Name" HeaderText="المجمع" ReadOnly="True" SortExpression="Name">
                                                    <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" />
                                                </asp:BoundField>
                                                <asp:BoundField DataField="DistName" HeaderText="المنطقة" ReadOnly="True" SortExpression="DistName">
                                                    <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" />
                                                </asp:BoundField>
                                                <asp:TemplateField HeaderText="إسم المحطة" SortExpression="staName">
                                                    <EditItemTemplate>
                                                        <asp:TextBox ID="txtSN" runat="server" Text='<%# Bind("staName") %>' 
                                                            MaxLength="50"></asp:TextBox>
                                                        <asp:RequiredFieldValidator ID="RequiredFieldValidator10" runat="server" ControlToValidate="txtSN"
                                                            Display="Dynamic" ErrorMessage="*" ForeColor="Red" ValidationGroup="gvs">*</asp:RequiredFieldValidator>
                                                    </EditItemTemplate>
                                                    <ItemTemplate>
                                                        <asp:Label ID="Label1" runat="server" Text='<%# Bind("staName") %>'></asp:Label>
                                                    </ItemTemplate>
                                                    <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" />
                                                </asp:TemplateField>
                                                <asp:TemplateField HeaderText="كود المحطة" SortExpression="Sta_Code">
                                                    <EditItemTemplate>
                                                        <asp:TextBox ID="txtSC" runat="server" Text='<%# Bind("Sta_Code") %>'></asp:TextBox>
                                                        <asp:RequiredFieldValidator ID="RequiredFieldValidator11" runat="server" ControlToValidate="txtSC"
                                                            Display="Dynamic" ErrorMessage="*" ForeColor="Red" ValidationGroup="gvs">*</asp:RequiredFieldValidator>
                                                    </EditItemTemplate>
                                                    <ItemTemplate>
                                                        <asp:Label ID="Label2" runat="server" Text='<%# Bind("Sta_Code") %>'></asp:Label>
                                                    </ItemTemplate>
                                                    <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" />
                                                </asp:TemplateField>
                                                <asp:CommandField CancelText="إلغاء" EditText="تعديل" ShowEditButton="True" UpdateText="تحديث"
                                                    ValidationGroup="gvs" />
                                                <asp:TemplateField ShowHeader="False">
                                                    <ItemTemplate>
                                                        <asp:LinkButton ID="lkdelete" runat="server" CausesValidation="False" CommandName="Delete"
                                                            Text="حذف"></asp:LinkButton>
                                                    </ItemTemplate>
                                                    <HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" />
                                                    <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" />
                                                </asp:TemplateField>
                                            </Columns>
                                            <FooterStyle CssClass="GridHeaderFooter" />
                                            <HeaderStyle CssClass="GridHeaderFooter" />
                                            <PagerStyle CssClass="GridPager" />
                                        </asp:GridView>
                                    </td>
                                </tr>
                                <tr>
                                    <td style="width: 89px">
                                        &nbsp;
                                    </td>
                                    <td>
                                        &nbsp;<asp:Button ID="btnNew" runat="server" CssClass="graybutton" OnClick="btnNew_Click1"
                                            Text="إضافة" />
                                    </td>
                                </tr>
                            </table>
                        </fieldset>
                    </asp:Panel>
                </div>
            </td>
        </tr>
    </table>
    <script src="../Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            $('#<%= txtScode.ClientID%>').blur(function () {
                var uname = $('#<%= txtScode.ClientID%>');
                var msgbox = $("#status");
                if (uname.val().length > 0) {
                    $.ajax({
                        type: "POST",
                        url: "Station.aspx/CheckCode",
                        data: "{'args': '" + uname.val() + "'}",
                        contentType: "application/json; charset=utf-8",
                        dataType: "json",
                        success: function (msg) {
                            if (msg.d == 'Available') {
                                uname.removeClass("notavailablecss");
                                uname.addClass("availablecss");
                                msgbox.html('<img src="../images/a.png"/> <font color="Green"> متاح </font>');

                            }


                            else {
                                uname.removeClass("availablecss");
                                uname.addClass("notavailablecss");
                                msgbox.html(msg.d);
                            }
                        }
                    });
                }
                else {

                    uname.addClass("notavailablecss");
                    msgbox.html('<font color="#cc0000">أدخل الكود</font>');
                }
            });

        });
        $(document).ready(function () {
            $('#<%= txtSName.ClientID%>').blur(function () {
                var uname = $('#<%= txtSName.ClientID%>');
                var msgbox = $("#statusbus");
                if (uname.val().length > 0) {
                    $.ajax({
                        type: "POST",
                        url: "Station.aspx/CheckName",
                        data: "{'args': '" + uname.val() + "'}",
                        contentType: "application/json; charset=utf-8",
                        dataType: "json",
                        success: function (msg) {
                            if (msg.d == 'Available') {
                                uname.removeClass("notavailablecss");
                                uname.addClass("availablecss");
                                msgbox.html('<img src="../images/a.png"/> <font color="Green"> متاح </font>');
                            }


                            else {
                                uname.removeClass("availablecss");
                                uname.addClass("notavailablecss");
                                msgbox.html(msg.d);
                            }
                        }
                    });
                }
                else {

                    uname.addClass("notavailablecss");
                    msgbox.html('<font color="#cc0000">أدخل الاسم</font>');
                }
            });
        });
        $(document).ready(function () {

            $("#btnNew").click(function () {
                $("#search").hide();
                $("#view").show();
            });

            $("#btnexit").click(function () {
                $("#view").hide();
                $("#search").show();
            });
        });


        //        $(document).ready(function () {
        //            $('#<%= ddCamp1.ClientID%>').change(function () {
        //                var id = $('#<%= ddCamp1.ClientID%> option:selected').val();
        //                $.ajax({
        //                    type: "GET",
        //                    url: "Station.aspx?Id=" + id,
        //                    contentType: "application/json; charset=utf-8",
        //                    global: false,
        //                    async: false,
        //                    dataType: "json",
        //                    success: function (jsonObj) {
        //                        html = "<option value='0'>اختيار </option>";
        //                        for (var k = 0; k < jsonObj.length; k++) {
        //                            html += "<option value ='" + jsonObj[k].Id + "'>" + jsonObj[k].Name + "</option>";
        //                        }
        //                        $(".Lstdist").html(html);
        //                    }
        //                });

        //            });
        //        });
        $(document).ready(function () {
            $("#btnexit").click(function () {

                $.ajax({
                    type: "GET",
                    url: "Station.aspx?type=" + "Bindcamp",
                    contentType: "application/json; charset=utf-8",
                    global: false,
                    async: false,
                    dataType: "json",
                    success: function (jsonObj) {
                        html = "<option value='0'>اختيار </option>";
                        for (var k = 0; k < jsonObj.length; k++) {
                            html += "<option value ='" + jsonObj[k].Id + "'>" + jsonObj[k].Name + "</option>";
                        }
                        $(".LstCamp").html(html);
                    }
                });

            });
        });
        $(document).ready(function () {
            $("#btnexit").click(function () {
                $("#<%= ddlDistrict.ClientID %> option").remove();
                html = "<option value='0'>اختيار </option>";
                $(".Lstdist").html(html);
            });
        });
        function Legend1_onclick() {

        }

    </script>
</asp:Content>
